package unimelb.filesync.common.misc;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum ProtocolContext {
    Server, Client;

    public static final String HOST = "Host";

    public static final String PORT = "Port";

    public static final String FILE_NAME = "FileName";

    public static final String BLOCK_SIZE = "BlockSize";

    public static final String ROLE = "Role";

    public static final String ROLE_SOURCE = "Source";

    public static final String ROLE_DESTINATION = "Destination";

    public static final String SERVER_SOCKET = "ServerSocket";

    public static final String HOT_LINE_CONNECTION = "HotLineConnection";

    public static final String FILE_CHANGE_POLL = "FileChangePoll";

    public static final String MAX_INSTRUCTION_SOCKETS = "MaxInstructionSocket";

    public static final String READ_MSG_QUEUE = "ReadMsgQueue";

    public static final String WRITE_MSG_QUEUE = "WriteMsgQueue";

    public static final String SENT_MSG_QUEUE = "SentMsgQueue";
    
    public static final String DEFAULT_QUEUE_SIZE = "QueueSize";
    
    public static final String SERVER_KEY_FILE = "ServerKeyFile";
    
    public static final String SERVER_KEY_SIZE = "ServerKeySize";
    
    public static final String SERVER_KEY_PAIR = "ServerKey";
    
    public static final String PASSWORD = "Password";
    
    public static final String SECRET_KEY = "SecretKey";
    
    public static final String PUBLIC_KEY = "PublicKey";
    
    private Map<String, Object> objectRegistry = new ConcurrentHashMap<String, Object>();

    private ProtocolContext() {
        addObject(FILE_CHANGE_POLL, 500);
        addObject(MAX_INSTRUCTION_SOCKETS, 4);
        addObject(DEFAULT_QUEUE_SIZE, 1024*1024);
        addObject(SERVER_KEY_FILE, "server");
        addObject(SERVER_KEY_SIZE, 2048);
    }

    @SuppressWarnings("unchecked")
    public <T> T getObject(String objectName) {
        if (!objectRegistry.containsKey(objectName)) {
            throw new RuntimeException(objectName + " does not exist");
        }
        return (T) objectRegistry.get(objectName);
    }

    public void addObject(String paramName, Object value) {
        objectRegistry.put(paramName, value);
    }
}
